<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Backend;
use App\Http\Controllers\Backend\Demand;
use App\Http\Controllers\Backend\Service;
use App\Http\Controllers\Backend\EdgeManage;
use App\Http\Controllers\Backend\UserManage;
use App\Http\Controllers\Backend\Order;

#######################################################################
#                   认证相关
#######################################################################
//注册
Route::post('register', [Backend\AuthController::class, 'register']);
//登录
Route::post('login', [Backend\AuthController::class, 'backendLogin']);

Route::middleware('auth:sanctum',"check.admin")->group(function () {
    Route::get('user', [Backend\AuthController::class, 'user']);
    Route::post('logout', [Backend\AuthController::class, 'logout']);
});


#######################################################################
#                   后台需求模块管理
#######################################################################
Route::group(['prefix' => 'demand', 'middleware' => ['auth:sanctum',"check.admin"]], function () {
    Route::get('search', [Demand\DemandController::class, 'search']);
    Route::post('store', [Demand\DemandController::class, 'store']);
    Route::post('delete/{id}', [Demand\DemandController::class, 'delete']);
    Route::post('edit/{id}', [Demand\DemandController::class, 'edit']);
});


#######################################################################
#                   后台服务模块管理
#######################################################################
Route::group(['prefix' => 'service', 'middleware' => ['auth:sanctum',"check.admin"]], function () {
    Route::get('search', [Service\ServiceController::class, 'search']);
    Route::post('store', [Service\ServiceController::class, 'store']);
    Route::post('delete/{id}', [Service\ServiceController::class, 'delete']);
    Route::post('edit/{id}', [Service\ServiceController::class, 'edit']);
});


#######################################################################
#                   后台用户管理模块
#######################################################################
Route::group(['middleware' => ['auth:sanctum',"check.admin"]], function () {

    // 用户信息管理
    Route::group(['prefix' => 'user'], function () {
        Route::get('search', [UserManage\UserController::class, 'search']);
        Route::post('store', [UserManage\UserController::class, 'store']);
        Route::post('delete/{id}', [UserManage\UserController::class, 'delete']);
        Route::post('edit/{id}', [UserManage\UserController::class, 'edit']);
    });

    //服务商信息管理
    Route::group(['prefix' => 'business'], function () {
        Route::get('search', [UserManage\BusinessController::class, 'search']);
        Route::post('store', [UserManage\BusinessController::class, 'store']);
        Route::post('delete/{id}', [UserManage\BusinessController::class, 'delete']);
        Route::post('edit/{id}', [UserManage\BusinessController::class, 'edit']);
    });

    //角色模块
    Route::group(['prefix' => 'role'], function () {
        Route::get('search', [UserManage\RoleController::class, 'search']);
        Route::post('store', [UserManage\RoleController::class, 'store']);
        Route::post('delete/{id}', [UserManage\RoleController::class, 'delete']);
        Route::post('edit/{id}', [UserManage\RoleController::class, 'edit']);
        Route::post('add-role-to-user', [UserManage\RoleController::class, 'addRoleToUser']);
    });
});


#######################################################################
#                   订单模块
#######################################################################
Route::group(['middleware' => ['auth:sanctum',"check.admin"]], function () {
    // 用户信息管理
    Route::group(['prefix' => 'order'], function () {
        Route::get('search', [Order\OrderController::class, 'search']);
        Route::post('store', [Order\OrderController::class, 'store']);
        Route::post('delete/{id}', [Order\OrderController::class, 'delete']);
        route::post('edit/{id}', [Order\OrderController::class, 'edit']);
    });
});


#######################################################################
#                   后台边缘模块管理
#######################################################################
Route::group(['middleware' => ['auth:sanctum',"check.admin"]], function () {

    // Banner管理
    Route::group(['prefix' => 'banner'], function () {
        Route::get('search', [EdgeManage\BannerController::class, 'search']);
        Route::post('store', [EdgeManage\BannerController::class, 'store']);
        Route::post('delete/{id}', [EdgeManage\BannerController::class, 'delete']);
        Route::post('edit/{id}', [EdgeManage\BannerController::class, 'edit']);
    });

    //cost_setting费用设置管理
    Route::group(['prefix' => 'cost-setting'], function () {
        Route::get('search', [EdgeManage\CostSettingController::class, 'search']);
        Route::post('store', [EdgeManage\CostSettingController::class, 'store']);
        Route::post('delete/{id}', [EdgeManage\CostSettingController::class, 'delete']);
        Route::post('edit/{id}', [EdgeManage\CostSettingController::class, 'edit']);
    });

    //类型管理
    Route::group(['prefix' => 'type'], function () {
        Route::get('search', [EdgeManage\TypeController::class, 'search']);
        Route::post('store', [EdgeManage\TypeController::class, 'store']);
        Route::post('delete/{id}', [EdgeManage\TypeController::class, 'delete']);
        Route::post('edit/{id}', [EdgeManage\TypeController::class, 'edit']);
    });

    //反馈问题管理
    Route::group(['prefix' => 'problem'], function () {
        Route::get('search', [EdgeManage\ProblemController::class, 'search']);
        Route::post('store', [EdgeManage\ProblemController::class, 'store']);
        Route::post('delete/{id}', [EdgeManage\ProblemController::class, 'delete']);
        Route::post('edit/{id}', [EdgeManage\ProblemController::class, 'edit']);
    });
});
